<?php

class user extends Model {

	public $table = 'users';
	
	public function getGroup()
	{
		$this->transformed['group'] = new user_group($this->group);
		
		
	}
	
	public static function isLoggedIn()
	{
		if(isset($_SESSION['id']))
		{
			return self::setUser();
		}
		else
		{
			return false;
		}
	}
	
	public static function isAdmin()
	{
		include(MODULE_DIR . 'user/config.php');
		if($user = self::isLoggedIn())
		{
			if($user->group->permissions == $config['modules']['user']['permissions']['admin'] || $user->permissions == $config['modules']['user']['permissions']['admin'])
			{
				return $user;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	
	public static function setUser()
	{
		if(isset($_SESSION['id']))
		{
			$currentUser = new user($_SESSION['id']);
		
			if($currentUser->password != md5($_SESSION['salt'] . $_SESSION['password']))
			{
				unset($currentUser);
			}

		}
		else
		{
		unset($currentUser);
		}
		
		if(isset($currentUser))
		{
			$currentUser->getGroup();
			return $currentUser;
		}
	}
}
?>